package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaWorkerMoneyChange;
import com.ruoyi.system.service.IJiajiaWorkerMoneyChangeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社工余额变动记录Controller
 * 
 * @author knd
 * @date 2021-11-02
 */
@Controller
@RequestMapping("/jiajia/workerMoneyChange")
public class JiajiaWorkerMoneyChangeController extends BaseController
{
    private String prefix = "jiajia/workerMoneyChange";

    @Autowired
    private IJiajiaWorkerMoneyChangeService jiajiaWorkerMoneyChangeService;

    @RequiresPermissions("jiajia:workerMoneyChange:view")
    @GetMapping()
    public String workerMoneyChange()
    {
        return prefix + "/workerMoneyChange";
    }

    /**
     * 查询社工余额变动记录列表
     */
    @RequiresPermissions("jiajia:workerMoneyChange:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaWorkerMoneyChange jiajiaWorkerMoneyChange)
    {
        startPage();
        List<JiajiaWorkerMoneyChange> list = jiajiaWorkerMoneyChangeService.selectJiajiaWorkerMoneyChangeList(jiajiaWorkerMoneyChange);
        return getDataTable(list);
    }

    /**
     * 导出社工余额变动记录列表
     */
    @RequiresPermissions("jiajia:workerMoneyChange:export")
    @Log(title = "社工余额变动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaWorkerMoneyChange jiajiaWorkerMoneyChange)
    {
        List<JiajiaWorkerMoneyChange> list = jiajiaWorkerMoneyChangeService.selectJiajiaWorkerMoneyChangeList(jiajiaWorkerMoneyChange);
        ExcelUtil<JiajiaWorkerMoneyChange> util = new ExcelUtil<JiajiaWorkerMoneyChange>(JiajiaWorkerMoneyChange.class);
        return util.exportExcel(list, "社工余额变动记录数据");
    }

    /**
     * 新增社工余额变动记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社工余额变动记录
     */
    @RequiresPermissions("jiajia:workerMoneyChange:add")
    @Log(title = "社工余额变动记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaWorkerMoneyChange jiajiaWorkerMoneyChange)
    {
        return toAjax(jiajiaWorkerMoneyChangeService.insertJiajiaWorkerMoneyChange(jiajiaWorkerMoneyChange));
    }

    /**
     * 修改社工余额变动记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaWorkerMoneyChange jiajiaWorkerMoneyChange = jiajiaWorkerMoneyChangeService.selectJiajiaWorkerMoneyChangeById(id);
        mmap.put("jiajiaWorkerMoneyChange", jiajiaWorkerMoneyChange);
        return prefix + "/edit";
    }

    /**
     * 修改保存社工余额变动记录
     */
    @RequiresPermissions("jiajia:workerMoneyChange:edit")
    @Log(title = "社工余额变动记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaWorkerMoneyChange jiajiaWorkerMoneyChange)
    {
        return toAjax(jiajiaWorkerMoneyChangeService.updateJiajiaWorkerMoneyChange(jiajiaWorkerMoneyChange));
    }

    /**
     * 删除社工余额变动记录
     */
    @RequiresPermissions("jiajia:workerMoneyChange:remove")
    @Log(title = "社工余额变动记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaWorkerMoneyChangeService.deleteJiajiaWorkerMoneyChangeByIds(ids));
    }
}
